package admin

import (
	"context"
	"gorm.io/gorm"
	DataHand "gostudy/system/datahand"
	"gostudy/system/models"
	"sync"
)

type UserService struct {
	DataHand *DataHand.AdminUserDataHand
}

var (
	instanceAdminUserService *UserService
	onceAdminUserService     sync.Once
)

func NewAdminUserService() *UserService {
	onceAdminUserService.Do(func() {
		instanceAdminUserService = &UserService{
			DataHand: DataHand.NewAdminUserDataHand(),
		}
	})
	return instanceAdminUserService
}

// 获取管理员
func (ser *UserService) GetAdminUsers(context context.Context, req models.AdminUserIndexReq) (db *gorm.DB) {
	return ser.DataHand.GetAdminUsers(context, req.Nickname, req.CreatedAt)
}

// 获取单个管理员用户信息
func (ser *UserService) GetAdminUser(conditions map[string]interface{}) (adminUser models.AdminUsers, err error) {
	adminUser, err = ser.DataHand.GetAdminUser(conditions)
	return
}

// 删除管理员
func (ser *UserService) DelAdminUser(id string) (err error) {
	return ser.DataHand.Del(map[string]interface{}{"uid": id})
}
